<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('已领取优惠券列表')"/>
</head>

<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="shop-product-add-form">
                <input type="hidden" name="memberId" th:value="${memberId}">
                <div class="select-list">
                    <ul>
                        <li>
                            优惠券标题：<input type="text" name="title"/>
                        </li>
                        <li>
                            <p style="width: 80px">优惠券类型： </p>
                            <select name="couponType" th:with="type=${@dict.getType('coupon_type')}">
                                <option value="">全部</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var prefix = ctx + "back/shopCoupon";
    var datas = [[${@dict.getType('is_enable')}]];
    var couponTypeDict = [[${@dict.getType('coupon_type')}]];
    var couponStatusDict = [[${@dict.getType('coupon_status')}]];
    var memberCouponStatusDict = [[${@dict.getType('member_coupon_status')}]];
    $(function () {
        var options = {
            url: prefix + "/searchGetList",
            modalName: "优惠券",
            columns: [
                {
                    field: 'id',
                    title: '优惠券ID',
                    visible: false
                },
                {
                    field: 'title',
                    title: '优惠券标题'
                },
                {
                    field: 'reachAmount',
                    title: '使用门槛',
                    formatter: function (value, row, index) {
                        if (0 == value) {
                            return "无使用门槛";
                        } else {
                            return "满" + value + "元可用";

                        }
                    }
                },
                {
                    field: 'couponType',
                    title: '优惠信息',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<span style="font-weight: bold">' + $.table.selectDictLabel(couponTypeDict, value) + '</span>');
                        if (1 == value) {
                            //满减
                            actions.push('<br/><label>面值：</label><span style="font-weight: bold">' + row.faceValue + '元</span>');
                        } else {
                            //折扣
                            actions.push('<br/><label>面值：</label><span style="font-weight: bold">' + row.discountValue + '折</span>');
                        }
                        return actions.join('');
                    }
                },
                {
                    field: 'memberCouponStatus',
                    title: '使用状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(memberCouponStatusDict, value);
                    }
                },
                {
                    field: 'createTime',
                    title: '领取时间',
                    sortable: true
                }
            ]
        };
        $.table.init(options);
    });

    function queryParams(params) {
        var search = $.table.queryParams(params);
        search.memberId = $('#memberId').val();
        return search;
    }

</script>
</body>
</html>